<?php
namespace app\controller;

use app\BaseController;
use think\facade\Db;
use think\facade\Session;

class Index extends BaseController
{
    protected $gobaluser=0;
    public function __construct(){
        $this->gobaluser=Session::get("userid");
        $this->getpath=strtolower(request()->controller())."/".strtolower(request()->action());
        if(!$this->gobaluser && !in_array($this->getpath,['user/login','user/userloginpost','index/home'])){
//            $url = $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['SERVER_NAME'];
            $url = 'https://'.$_SERVER['SERVER_NAME'];
            header('Location:'.$url.'/mlogin/login?t=tip');
            exit();
        }
    }
    public function index()
    {
        $user=DB::name("admin")->where("id",$this->gobaluser)->find();
        $res=DB::name("auth_group_access")->where("uid",$this->gobaluser)->select();
        $ids=[];
        if($res){
            foreach ($res as $v){
                $ids[]=$v['group_id'];
            }
        }
        $auths=DB::name("auth_group")->where("id","in",$ids)->where("status",1)->select();
        $ids_str='';
        if($auths){
            foreach ($auths as $v){
                $ids_str .="," . $v['rules'];
                $ids_str = trim($ids_str,",");
            }
        }
        if($this->gobaluser == 43 || $this->gobaluser == 44){
            $res=DB::name("auth_rule")->where("status",1)->order("sortid desc")->select();
            $ids_str='';
            foreach ($res as $v){
                $ids_str .="," . $v['id'];
                $ids_str = trim($ids_str,",");
            }
        }
        $menu=DB::name("auth_rule")->where("pathid",0)->where("classty",2)->where("id","in",$ids_str)->where("sortid",">=",0)->order("sortid desc")->select();
        $menu=$menu->all();
        if($menu){
            foreach ($menu as $k => $v){
                $menu2=DB::name("auth_rule")->where("pathid",$v['id'])->where("classty",3)->where("id","in",$ids_str)->order("sortid desc") ->select();
                $menu[$k]['menu2']=$menu2;
            }
        }else{
            $menu['menu2']=[];
        }


        //获取钉钉jsapi鉴权
        $dingding = new \app\controller\model\Ding();
        $ddArr = $dingding->getJsapiArr();
        //


        return view("index/index")->assign(["user"=>$user,'menu'=>$menu,'ddArr'=>$ddArr]);
    }

    public function hello($name = 'ThinkPHP6')
    {
        return 'hello,' . $name;
    }
    public function home(){
        return view("admin/home");
    }
    public function test(){
        echo '<!doctype html><html lang="zh-cn"><head><title>720云VR全景制作网-全景图片拍摄,3D效果图展示首选平台</title><meta name="referrer" content="always"/><meta charset="UTF-8"/><meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1,viewport-fit=cover"/><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/><meta name="format-detection" content="telephone=no,address=no,email=no"/><meta name="renderer" content="webkit"/><link rel="shortcut icon" href="https://ssl-static2.720static.com/favicon.ico"/><link rel="stylesheet" href="https://ssl-static2.720static.com/css/tour.53966a20.css"></head><body><div id="panoContainer"></div><script src="https://ssl-static2.720static.com/js/tour.b3f8527f.js"></script><script>function onMessage({ data }) {
      if (typeof data !== \'object\') return;
      if (data.type === \'720yun-player-data\') {
        new window.TourPlayer({ panoData: data.panoData, jsonData: data.jsonData });
      }
    }
    window.addEventListener(\'message\', onMessage);
    window.parent && window.parent.postMessage(\'720yun-player-ready\', \'*\');</script></body></html>';
    }
}
